import{c as classesToSelector}from"../shared/classes-to-selector.min.mjs";import{c as createElementIfNotDefined}from"../shared/create-element-if-not-defined.min.mjs";import{f as elementOuterSize,g as elementIndex,a as elementParents}from"../shared/utils.min.mjs";function Pagination(a){let{swiper:e,extendParams:s,on:l,emit:t}=a;const i="swiper-pagination";let n;s({pagination:{el:null,bulletElement:"span",clickable:!1,hideOnClick:!1,renderBullet:null,renderProgressbar:null,renderFraction:null,renderCustom:null,progressbarOpposite:!1,type:"bullets",dynamicBullets:!1,dynamicMainBullets:1,formatFractionCurrent:a=>a,formatFractionTotal:a=>a,bulletClass:`${i}-bullet`,bulletActiveClass:`${i}-bullet-active`,modifierClass:`${i}-`,currentClass:`${i}-current`,totalClass:`${i}-total`,hiddenClass:`${i}-hidden`,progressbarFillClass:`${i}-progressbar-fill`,progressbarOppositeClass:`${i}-progressbar-opposite`,clickableClass:`${i}-clickable`,lockClass:`${i}-lock`,horizontalClass:`${i}-horizontal`,verticalClass:`${i}-vertical`,paginationDisabledClass:`${i}-disabled`}}),e.pagination={el:null,bullets:[]};let r=0;const o=a=>(Array.isArray(a)?a:[a]).filter((a=>!!a));function p(){return!e.params.pagination.el||!e.pagination.el||Array.isArray(e.pagination.el)&&0===e.pagination.el.length}function c(a,s){const{bulletActiveClass:l}=e.params.pagination;a&&(a=a[("prev"===s?"previous":"next")+"ElementSibling"])&&(a.classList.add(`${l}-${s}`),(a=a[("prev"===s?"previous":"next")+"ElementSibling"])&&a.classList.add(`${l}-${s}-${s}`))}function d(a){const s=a.target.closest(classesToSelector(e.params.pagination.bulletClass));if(!s)return;a.preventDefault();const l=elementIndex(s)*e.params.slidesPerGroup;if(e.params.loop){if(e.realIndex===l)return;e.slideToLoop(l)}else e.slideTo(l)}function u(){const a=e.rtl,s=e.params.pagination;if(p())return;let l,i,d=e.pagination.el;d=o(d);const u=e.virtual&&e.params.virtual.enabled?e.virtual.slides.length:e.slides.length,m=e.params.loop?Math.ceil(u/e.params.slidesPerGroup):e.snapGrid.length;if(e.params.loop?(i=e.previousRealIndex||0,l=e.params.slidesPerGroup>1?Math.floor(e.realIndex/e.params.slidesPerGroup):e.realIndex):void 0!==e.snapIndex?(l=e.snapIndex,i=e.previousSnapIndex):(i=e.previousIndex||0,l=e.activeIndex||0),"bullets"===s.type&&e.pagination.bullets&&e.pagination.bullets.length>0){const t=e.pagination.bullets;let o,p,u;if(s.dynamicBullets&&(n=elementOuterSize(t[0],e.isHorizontal()?"width":"height",!0),d.forEach((a=>{a.style[e.isHorizontal()?"width":"height"]=n*(s.dynamicMainBullets+4)+"px"})),s.dynamicMainBullets>1&&void 0!==i&&(r+=l-(i||0),r>s.dynamicMainBullets-1?r=s.dynamicMainBullets-1:r<0&&(r=0)),o=Math.max(l-r,0),p=o+(Math.min(t.length,s.dynamicMainBullets)-1),u=(p+o)/2),t.forEach((a=>{const e=[...["","-next","-next-next","-prev","-prev-prev","-main"].map((a=>`${s.bulletActiveClass}${a}`))].map((a=>"string"==typeof a&&a.includes(" ")?a.split(" "):a)).flat();a.classList.remove(...e)})),d.length>1)t.forEach((a=>{const t=elementIndex(a);t===l?a.classList.add(...s.bulletActiveClass.split(" ")):e.isElement&&a.setAttribute("part","bullet"),s.dynamicBullets&&(t>=o&&t<=p&&a.classList.add(...`${s.bulletActiveClass}-main`.split(" ")),t===o&&c(a,"prev"),t===p&&c(a,"next"))}));else{const a=t[l];if(a&&a.classList.add(...s.bulletActiveClass.split(" ")),e.isElement&&t.forEach(((a,e)=>{a.setAttribute("part",e===l?"bullet-active":"bullet")})),s.dynamicBullets){const a=t[o],e=t[p];for(let a=o;a<=p;a+=1)t[a]&&t[a].classList.add(...`${s.bulletActiveClass}-main`.split(" "));c(a,"prev"),c(e,"next")}}if(s.dynamicBullets){const l=Math.min(t.length,s.dynamicMainBullets+4),i=(n*l-n)/2-u*n,r=a?"right":"left";t.forEach((a=>{a.style[e.isHorizontal()?r:"top"]=`${i}px`}))}}d.forEach(((a,i)=>{if("fraction"===s.type&&(a.querySelectorAll(classesToSelector(s.currentClass)).forEach((a=>{a.textContent=s.formatFractionCurrent(l+1)})),a.querySelectorAll(classesToSelector(s.totalClass)).forEach((a=>{a.textContent=s.formatFractionTotal(m)}))),"progressbar"===s.type){let t;t=s.progressbarOpposite?e.isHorizontal()?"vertical":"horizontal":e.isHorizontal()?"horizontal":"vertical";const i=(l+1)/m;let n=1,r=1;"horizontal"===t?n=i:r=i,a.querySelectorAll(classesToSelector(s.progressbarFillClass)).forEach((a=>{a.style.transform=`translate3d(0,0,0) scaleX(${n}) scaleY(${r})`,a.style.transitionDuration=`${e.params.speed}ms`}))}"custom"===s.type&&s.renderCustom?(a.innerHTML=s.renderCustom(e,l+1,m),0===i&&t("paginationRender",a)):(0===i&&t("paginationRender",a),t("paginationUpdate",a)),e.params.watchOverflow&&e.enabled&&a.classList[e.isLocked?"add":"remove"](s.lockClass)}))}function m(){const a=e.params.pagination;if(p())return;const s=e.virtual&&e.params.virtual.enabled?e.virtual.slides.length:e.grid&&e.params.grid.rows>1?e.slides.length/Math.ceil(e.params.grid.rows):e.slides.length;let l=e.pagination.el;l=o(l);let i="";if("bullets"===a.type){let l=e.params.loop?Math.ceil(s/e.params.slidesPerGroup):e.snapGrid.length;e.params.freeMode&&e.params.freeMode.enabled&&l>s&&(l=s);for(let s=0;s<l;s+=1)a.renderBullet?i+=a.renderBullet.call(e,s,a.bulletClass):i+=`<${a.bulletElement} ${e.isElement?'part="bullet"':""} class="${a.bulletClass}"></${a.bulletElement}>`}"fraction"===a.type&&(i=a.renderFraction?a.renderFraction.call(e,a.currentClass,a.totalClass):`<span class="${a.currentClass}"></span> / <span class="${a.totalClass}"></span>`),"progressbar"===a.type&&(i=a.renderProgressbar?a.renderProgressbar.call(e,a.progressbarFillClass):`<span class="${a.progressbarFillClass}"></span>`),e.pagination.bullets=[],l.forEach((s=>{"custom"!==a.type&&(s.innerHTML=i||""),"bullets"===a.type&&e.pagination.bullets.push(...s.querySelectorAll(classesToSelector(a.bulletClass)))})),"custom"!==a.type&&t("paginationRender",l[0])}function g(){e.params.pagination=createElementIfNotDefined(e,e.originalParams.pagination,e.params.pagination,{el:"swiper-pagination"});const a=e.params.pagination;if(!a.el)return;let s;"string"==typeof a.el&&e.isElement&&(s=e.el.querySelector(a.el)),s||"string"!=typeof a.el||(s=[...document.querySelectorAll(a.el)]),s||(s=a.el),s&&0!==s.length&&(e.params.uniqueNavElements&&"string"==typeof a.el&&Array.isArray(s)&&s.length>1&&(s=[...e.el.querySelectorAll(a.el)],s.length>1&&(s=s.filter((a=>elementParents(a,".swiper")[0]===e.el))[0])),Array.isArray(s)&&1===s.length&&(s=s[0]),Object.assign(e.pagination,{el:s}),s=o(s),s.forEach((s=>{"bullets"===a.type&&a.clickable&&s.classList.add(...(a.clickableClass||"").split(" ")),s.classList.add(a.modifierClass+a.type),s.classList.add(e.isHorizontal()?a.horizontalClass:a.verticalClass),"bullets"===a.type&&a.dynamicBullets&&(s.classList.add(`${a.modifierClass}${a.type}-dynamic`),r=0,a.dynamicMainBullets<1&&(a.dynamicMainBullets=1)),"progressbar"===a.type&&a.progressbarOpposite&&s.classList.add(a.progressbarOppositeClass),a.clickable&&s.addEventListener("click",d),e.enabled||s.classList.add(a.lockClass)})))}function b(){const a=e.params.pagination;if(p())return;let s=e.pagination.el;s&&(s=o(s),s.forEach((s=>{s.classList.remove(a.hiddenClass),s.classList.remove(a.modifierClass+a.type),s.classList.remove(e.isHorizontal()?a.horizontalClass:a.verticalClass),a.clickable&&(s.classList.remove(...(a.clickableClass||"").split(" ")),s.removeEventListener("click",d))}))),e.pagination.bullets&&e.pagination.bullets.forEach((e=>e.classList.remove(...a.bulletActiveClass.split(" "))))}l("changeDirection",(()=>{if(!e.pagination||!e.pagination.el)return;const a=e.params.pagination;let{el:s}=e.pagination;s=o(s),s.forEach((s=>{s.classList.remove(a.horizontalClass,a.verticalClass),s.classList.add(e.isHorizontal()?a.horizontalClass:a.verticalClass)}))})),l("init",(()=>{!1===e.params.pagination.enabled?f():(g(),m(),u())})),l("activeIndexChange",(()=>{void 0===e.snapIndex&&u()})),l("snapIndexChange",(()=>{u()})),l("snapGridLengthChange",(()=>{m(),u()})),l("destroy",(()=>{b()})),l("enable disable",(()=>{let{el:a}=e.pagination;a&&(a=o(a),a.forEach((a=>a.classList[e.enabled?"remove":"add"](e.params.pagination.lockClass))))})),l("lock unlock",(()=>{u()})),l("click",((a,s)=>{const l=s.target,i=o(e.pagination.el);if(e.params.pagination.el&&e.params.pagination.hideOnClick&&i&&i.length>0&&!l.classList.contains(e.params.pagination.bulletClass)){if(e.navigation&&(e.navigation.nextEl&&l===e.navigation.nextEl||e.navigation.prevEl&&l===e.navigation.prevEl))return;const a=i[0].classList.contains(e.params.pagination.hiddenClass);t(!0===a?"paginationShow":"paginationHide"),i.forEach((a=>a.classList.toggle(e.params.pagination.hiddenClass)))}}));const f=()=>{e.el.classList.add(e.params.pagination.paginationDisabledClass);let{el:a}=e.pagination;a&&(a=o(a),a.forEach((a=>a.classList.add(e.params.pagination.paginationDisabledClass)))),b()};Object.assign(e.pagination,{enable:()=>{e.el.classList.remove(e.params.pagination.paginationDisabledClass);let{el:a}=e.pagination;a&&(a=o(a),a.forEach((a=>a.classList.remove(e.params.pagination.paginationDisabledClass)))),g(),m(),u()},disable:f,render:m,update:u,init:g,destroy:b})}export{Pagination as default};
//# sourceMappingURL=pagination.min.mjs.map